package com.suixun.service.common.impl;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;

import com.suixun.dao.impl.BaseDaoImpl;
import com.suixun.dao.model.PageGrid;
import com.suixun.dao.model.PageQueryModel;
import com.suixun.service.common.CommonService;


@Service
public class CommonServiceImpl implements CommonService {

	@Resource
	private BaseDaoImpl baseDaoImpl;

	@Override
	public <E> List<E> selectList(String statement,
			Map<String, String> parameter) {
		return baseDaoImpl.selectList(statement, parameter);
	}

	@Override
	public <K, V> Map<K, V> selectMap(String statement,
			Map<String, String> parameter, String mapKey) {
		return baseDaoImpl.selectMap(statement, parameter, mapKey);
	}

	@Override
	public <T> T selectOne(String statement, Map<String, String> parameter) {
		return baseDaoImpl.selectOne(statement, parameter);
	}

	@Override
	public PageGrid pageForObject(String statementName,
			PageQueryModel parameterObject) {
		return baseDaoImpl.pageForObject(statementName, parameterObject);
	}

	@Override
	public int delete(String statement) {
		return baseDaoImpl.delete(statement);
	}

	@Override
	public int delete(String statement, List lst) {
		return baseDaoImpl.delete(statement, lst);
	}

	
	/**
	 * 通用下拉框初始化方法！
	 * ex：
	 * 
	 *<select id="getYearList" resultType="string">
	 *	<option value="key">value</option>
	 *	<option value="key">value</option>
	 *	<option value="key">value</option>
	 *</select>
	 * 
	 * @author G
	 */
	@Override
	public Map<String, String> initDropdownbox(
			String statement,
			Map<String, String> parameter) {
		
		List<Map<String,String>> list = baseDaoImpl.selectList(statement, parameter);
		
		//LinkedHashMap, 先进先出,由于保证书顺序
		Map<String,String>map =  new LinkedHashMap<String,String>();
				
		for(Map<String,String> e:list){			
			map.put(e.get("key"),e.get("value"));
		}
				
		return map;
	}
}
